<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>01-SpringBoot高级 | 阿毛的博客</title><meta name="keywords" content="springBoot"><meta name="author" content="myl"><meta name="copyright" content="myl"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="01-SpringBoot高级-今日内容 SpringBoot自定配置 SpringBoot事件监听 SpringBoot流程分析 SpringBoot监控 SpringBoot部署  02-SpringBoot自动配置-Condition-1 Condition是Spring4.0后引入的条件化配置接口，通过实现Condition接口可以完成有条件的加载相应的Bean @Conditional要">
<meta property="og:type" content="article">
<meta property="og:title" content="01-SpringBoot高级">
<meta property="og:url" content="https://gitee.com/tgreen/myl-mm.git/2022/05/09/02-SpringBoot%E9%AB%98%E7%BA%A7/index.html">
<meta property="og:site_name" content="阿毛的博客">
<meta property="og:description" content="01-SpringBoot高级-今日内容 SpringBoot自定配置 SpringBoot事件监听 SpringBoot流程分析 SpringBoot监控 SpringBoot部署  02-SpringBoot自动配置-Condition-1 Condition是Spring4.0后引入的条件化配置接口，通过实现Condition接口可以完成有条件的加载相应的Bean @Conditional要">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg">
<meta property="article:published_time" content="2022-05-09T09:03:06.874Z">
<meta property="article:modified_time" content="2022-05-09T11:31:52.591Z">
<meta property="article:author" content="myl">
<meta property="article:tag" content="springBoot">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg"><link rel="shortcut icon" href="/myl-mm/img/favicon.png"><link rel="canonical" href="https://gitee.com/tgreen/myl-mm.git/2022/05/09/02-SpringBoot%E9%AB%98%E7%BA%A7/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myl-mm/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/myl-mm/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '01-SpringBoot高级',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-09 19:31:52'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myl-mm/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/myl-mm/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/myl-mm/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myl-mm/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/long1.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/myl-mm/">阿毛的博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myl-mm/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">01-SpringBoot高级</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-05-09T09:03:06.874Z" title="发表于 2022-05-09 17:03:06">2022-05-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-09T11:31:52.591Z" title="更新于 2022-05-09 19:31:52">2022-05-09</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myl-mm/categories/spring/">spring</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="01-SpringBoot高级"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="01-SpringBoot高级-今日内容"><a href="#01-SpringBoot高级-今日内容" class="headerlink" title="01-SpringBoot高级-今日内容"></a><strong>01-SpringBoot高级-今日内容</strong></h2><ul>
<li>SpringBoot自定配置</li>
<li>SpringBoot事件监听</li>
<li>SpringBoot流程分析</li>
<li>SpringBoot监控</li>
<li>SpringBoot部署</li>
</ul>
<h2 id="02-SpringBoot自动配置-Condition-1"><a href="#02-SpringBoot自动配置-Condition-1" class="headerlink" title="02-SpringBoot自动配置-Condition-1"></a><strong>02-SpringBoot自动配置-Condition-1</strong></h2><p> Condition是Spring4.0后引入的条件化配置接口，通过实现Condition接口可以完成有条件的加载相应的Bean</p>
<p>@Conditional要配和Condition的实现类（ClassCondition）进行使用</p>
<ul>
<li>ClassCondition</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ClassCondition</span> <span class="keyword">implements</span> <span class="title class_">Condition</span> &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> context 上下文对象。用于获取环境，IOC容器，ClassLoader对象</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> metadata 注解元对象。 可以用于获取注解定义的属性值</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">matches</span><span class="params">(ConditionContext context, AnnotatedTypeMetadata metadata)</span> &#123;</span><br><span class="line">      </span><br><span class="line">        <span class="comment">//1.需求： 导入Jedis坐标后创建Bean</span></span><br><span class="line">        <span class="comment">//思路：判断redis.clients.jedis.Jedis.class文件是否存在</span></span><br><span class="line">        <span class="type">boolean</span> <span class="variable">flag</span> <span class="operator">=</span> <span class="literal">true</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Class&lt;?&gt; cls = Class.forName(<span class="string">&quot;redis.clients.jedis.Jedis&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            flag = <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> flag;</span><br><span class="line">      </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>UserConfig</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserConfig</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="meta">@Conditional(ClassCondition.class)</span></span><br><span class="line">    <span class="keyword">public</span> User <span class="title function_">user</span><span class="params">()</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">User</span>();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>测试</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">SpringbootConditionApplication</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//启动SpringBoot的应用，返回Spring的IOC容器</span></span><br><span class="line">        <span class="type">ConfigurableApplicationContext</span> <span class="variable">context</span> <span class="operator">=</span> SpringApplication.run(SpringbootConditionApplication.class, args);</span><br><span class="line"></span><br><span class="line">        <span class="type">Object</span> <span class="variable">user</span> <span class="operator">=</span> context.getBean(<span class="string">&quot;user&quot;</span>);</span><br><span class="line">        System.out.println(user);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="03-SpringBoot自动配置-Condition-2"><a href="#03-SpringBoot自动配置-Condition-2" class="headerlink" title="03-SpringBoot自动配置-Condition-2"></a><strong>03-SpringBoot自动配置-Condition-2</strong></h2><p> 需求：将类的判断定义为动态的。判断哪个字节码文件存在可以动态指定。</p>
<p>自定义条件注解类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Conditional;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.*;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">@Target(&#123;ElementType.TYPE, ElementType.METHOD&#125;)</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="meta">@Conditional(ClassCondition.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> ConditionOnClass &#123;</span><br><span class="line">    String[] value();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>注意：</strong>此处@ConditionOnClass为自定义注解</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserConfig</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="comment">//@Conditional(ClassCondition.class)</span></span><br><span class="line">    <span class="meta">@ConditionOnClass(&quot;com.alibaba.fastjson.JSON&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> User <span class="title function_">user</span><span class="params">()</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">User</span>();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="meta">@ConditionalOnProperty(name = &quot;itcast&quot;,havingValue = &quot;itheima&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> User <span class="title function_">user2</span><span class="params">()</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">User</span>();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>测试User对象的创建</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">SpringbootConditionApplication</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//启动SpringBoot的应用，返回Spring的IOC容器</span></span><br><span class="line">        <span class="type">ConfigurableApplicationContext</span> <span class="variable">context</span> <span class="operator">=</span> SpringApplication.run(SpringbootConditionApplication.class, args);</span><br><span class="line"></span><br><span class="line">        <span class="type">Object</span> <span class="variable">user</span> <span class="operator">=</span> context.getBean(<span class="string">&quot;user&quot;</span>);</span><br><span class="line">        System.out.println(user);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>查看条件注解源码</p>
<p><img src="/myl-mm/img/1571383973124.png" alt="1571383973124"></p>
<p><strong>SpringBoot 提供的常用条件注解：</strong></p>
<p>ConditionalOnProperty：判断配置文件中是否有对应属性和值才初始化Bean</p>
<p>ConditionalOnClass：判断环境中是否有对应字节码文件才初始化Bean</p>
<p>ConditionalOnMissingBean：判断环境中没有对应Bean才初始化Bean</p>
<h2 id="04-SpringBoot自动配置-切换内置web服务器"><a href="#04-SpringBoot自动配置-切换内置web服务器" class="headerlink" title="04-SpringBoot自动配置-切换内置web服务器"></a><strong>04-SpringBoot自动配置-切换内置web服务器</strong></h2><p>查看继承关系图</p>
<p><img src="/myl-mm/img/1571306414687.png" alt="1571306414687"></p>
<p>排除Tomcat</p>
<p><img src="/myl-mm/img/1571306366201.png" alt="1571306366201"></p>
<p>pom文件中的排除依赖效果</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">           <span class="comment">&lt;!--排除tomcat依赖--&gt;</span></span><br><span class="line">           <span class="tag">&lt;<span class="name">exclusions</span>&gt;</span></span><br><span class="line">               <span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">                   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-tomcat<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">                   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">               <span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;/<span class="name">exclusions</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line">       <span class="comment">&lt;!--引入jetty的依赖--&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-jetty<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="05-SpringBoot自动配置-Enable注解原理"><a href="#05-SpringBoot自动配置-Enable注解原理" class="headerlink" title="05-SpringBoot自动配置-Enable注解原理"></a>05-SpringBoot自动配置-Enable注解原理</h2><ul>
<li><p>SpringBoot不能直接获取在其他工程中定义的Bean</p>
<p>演示代码：</p>
<p>springboot-enable工程</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@ComponentScan</span> 扫描范围：当前引导类所在包及其子包</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment">   * com.itheima.springbootenable</span></span><br><span class="line"><span class="comment">   * com.itheima.config</span></span><br><span class="line"><span class="comment">   * //1.使用<span class="doctag">@ComponentScan</span>扫描com.itheima.config包</span></span><br><span class="line"><span class="comment">   * //2.可以使用<span class="doctag">@Import</span>注解，加载类。这些类都会被Spring创建，并放入IOC容器</span></span><br><span class="line"><span class="comment">   * //3.可以对Import注解进行封装。</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">//@ComponentScan(&quot;com.itheima.config&quot;)</span></span><br><span class="line">  <span class="comment">//@Import(UserConfig.class)</span></span><br><span class="line">  <span class="meta">@EnableUser</span></span><br><span class="line">  <span class="meta">@SpringBootApplication</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">SpringbootEnableApplication</span> &#123;</span><br><span class="line">  </span><br><span class="line">      <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">          <span class="type">ConfigurableApplicationContext</span> <span class="variable">context</span> <span class="operator">=</span> SpringApplication.run(SpringbootEnableApplication.class, args);</span><br><span class="line">  </span><br><span class="line">       <span class="comment">//获取Bean</span></span><br><span class="line">          <span class="type">Object</span> <span class="variable">user</span> <span class="operator">=</span> context.getBean(<span class="string">&quot;user&quot;</span>);</span><br><span class="line">          System.out.println(user);</span><br><span class="line">  </span><br><span class="line">  	&#125;</span><br><span class="line">  </span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<p>pom中引入springboot-enable-other</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">           &lt;groupId&gt;com.itheima&lt;/groupId&gt;</span><br><span class="line">         &lt;artifactId&gt;springboot-enable-other&lt;/artifactId&gt;</span><br><span class="line">           &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;</span><br><span class="line">     &lt;/dependency&gt;</span><br></pre></td></tr></table></figure>

<p>springboot-enable-other工程</p>
<p><strong>UserConfig</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserConfig</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">  <span class="keyword">public</span> User <span class="title function_">user</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">User</span>();</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>EnableUser注解类</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">  <span class="keyword">import</span> org.springframework.context.annotation.Import;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">import</span> java.lang.annotation.*;</span><br><span class="line">  </span><br><span class="line">  <span class="meta">@Target(ElementType.TYPE)</span></span><br><span class="line">  <span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line">  <span class="meta">@Import(UserConfig.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> EnableUser &#123;</span><br><span class="line">  </span><br></pre></td></tr></table></figure></li>
</ul>
<p>}</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">  </span><br><span class="line">  **原因**：@ComponentScan 扫描范围：当前引导类所在包及其子包</span><br><span class="line">  </span><br><span class="line">  **三种解决方案：**</span><br><span class="line">  </span><br><span class="line">  1.使用@ComponentScan扫描com.itheima.config包 </span><br><span class="line">  </span><br><span class="line">  2.可以使用@Import注解，加载类。这些类都会被Spring创建，并放入IOC容器</span><br><span class="line">  </span><br><span class="line">  3.可以对Import注解进行封装。</span><br><span class="line">  </span><br><span class="line">  **重点：Enable注解底层原理是使用@Import注解实现Bean的动态加载**</span><br><span class="line"></span><br><span class="line">## **06-SpringBoot自动配置-@Import详解**</span><br><span class="line"></span><br><span class="line">@Enable*底层依赖于@Import注解导入一些类，使用@Import导入的类会被Spring加载到IOC容器中。而@Import提供4中用法：</span><br><span class="line"></span><br><span class="line">①导入Bean</span><br><span class="line"></span><br><span class="line">②导入配置类</span><br><span class="line"></span><br><span class="line">③导入 ImportSelector 实现类。一般用于加载配置文件中的类</span><br><span class="line"></span><br><span class="line">④导入 ImportBeanDefinitionRegistrar 实现类。</span><br><span class="line"></span><br><span class="line">- 导入Bean  @Import(User.class)</span><br><span class="line"></span><br><span class="line">- 导入配置类  @Import(UserConfig.class)</span><br><span class="line"></span><br><span class="line">- 导入 ImportSelector 实现类   @Import(MyImportSelector.class)</span><br><span class="line"></span><br><span class="line">  MyImportSelector</span><br><span class="line"></span><br><span class="line">  ```java</span><br><span class="line">  public class MyImportSelector implements ImportSelector &#123;</span><br><span class="line">      @Override</span><br><span class="line">      public String[] selectImports(AnnotationMetadata importingClassMetadata) &#123;</span><br><span class="line">          return new String[]&#123;&quot;com.itheima.domain.User&quot;, &quot;com.itheima.domain.Role&quot;&#125;;</span><br><span class="line">      &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>导入 ImportBeanDefinitionRegistrar 实现类。@Import({MyImportBeanDefinitionRegistrar.class})</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyImportBeanDefinitionRegistrar</span> <span class="keyword">implements</span> <span class="title class_">ImportBeanDefinitionRegistrar</span> &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">registerBeanDefinitions</span><span class="params">(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry)</span> &#123;</span><br><span class="line">        <span class="type">AbstractBeanDefinition</span> <span class="variable">beanDefinition</span> <span class="operator">=</span> BeanDefinitionBuilder.rootBeanDefinition(User.class).getBeanDefinition();</span><br><span class="line">        registry.registerBeanDefinition(<span class="string">&quot;user&quot;</span>, beanDefinition);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>SpringbootEnableApplication测试代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br></pre></td></tr></table></figure></li>
</ul>
<ul>
<li>Import4中用法：<ul>
<li><ol>
<li>导入Bean</li>
</ol>
</li>
<li><ol start="2">
<li>导入配置类</li>
</ol>
</li>
<li><ol start="3">
<li>导入ImportSelector的实现类。</li>
</ol>
</li>
<li><ol start="4">
<li>导入ImportBeanDefinitionRegistrar实现类<br>*&#x2F;</li>
</ol>
</li>
</ul>
</li>
</ul>
<p>  &#x2F;&#x2F;@Import(User.class)<br>  &#x2F;&#x2F;@Import(UserConfig.class)<br>  &#x2F;&#x2F;@Import(MyImportSelector.class)<br>  &#x2F;&#x2F;@Import({MyImportBeanDefinitionRegistrar.class})</p>
<p>  @SpringBootApplication<br>  public class SpringbootEnableApplication {</p>
<pre><code>  public static void main(String[] args) &#123;
      ConfigurableApplicationContext context = SpringApplication.run(SpringbootEnableApplication.class, args);
  
      /*//获取Bean
      Object user = context.getBean(&quot;user&quot;);
      System.out.println(user);*/
  
      /*User user = context.getBean(User.class);
      System.out.println(user);
  
      Role role = context.getBean(Role.class);
      System.out.println(role);*/
  
    /*  Object user = context.getBean(&quot;user&quot;);
      System.out.println(user);*/
   Map&lt;String, User&gt; map = context.getBeansOfType(User.class);
      System.out.println(map);
  
  &#125;
</code></pre>
<p>  }<br>  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line">@EnableAutoConfiguration中使用的是第三种方式：@Import(AutoConfigurationImportSelector.class)</span><br><span class="line"></span><br><span class="line">## **07-SpringBoot自动配置-@EnableAutoConfiguration详解**</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">![1571387384701](img/1571387384701.png)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">- @EnableAutoConfiguration 注解内部使用 @Import(AutoConfigurationImportSelector.**class**)来加载配置类。 </span><br><span class="line"></span><br><span class="line">- 配置文件位置：META-INF/spring.factories，该配置文件中定义了大量的配置类，当 SpringBoot 应用启动时，会自动加载这些配置类，初始化Bean</span><br><span class="line"></span><br><span class="line">- 并不是所有的Bean都会被初始化，在配置类中使用Condition来加载满足条件的Bean</span><br><span class="line"></span><br><span class="line">## **08-SpringBoot自动配置-自定义starter步骤分析**</span><br><span class="line"></span><br><span class="line">**需求：**自定义redis-starter。要求当导入redis坐标时，SpringBoot自动创建Jedis的Bean。</span><br><span class="line"></span><br><span class="line">**步骤：**</span><br><span class="line"></span><br><span class="line">①创建 redis-spring-boot-autoconfigure 模块</span><br><span class="line"></span><br><span class="line">②创建 redis-spring-boot-starter 模块,依赖 redis-spring-boot-autoconfigure的模块</span><br><span class="line"></span><br><span class="line">③在 redis-spring-boot-autoconfigure 模块中初始化 Jedis 的 Bean。并定义META-INF/spring.factories 文件</span><br><span class="line"></span><br><span class="line">④在测试模块中引入自定义的 redis-starter 依赖，测试获取 Jedis 的Bean，操作 redis。</span><br><span class="line"></span><br><span class="line">## **09-SpringBoot自动配置-自定义starter实现-1**</span><br><span class="line"></span><br><span class="line">1. **创建redis-spring-boot-starter工程**</span><br><span class="line"></span><br><span class="line">​         pom文件中引入redis-spring-boot-autoconfigure</span><br><span class="line"></span><br><span class="line">​```xml</span><br><span class="line"> &lt;!--引入configure--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;com.itheima&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;redis-spring-boot-autoconfigure&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br></pre></td></tr></table></figure></p>
<ol start="2">
<li><strong>创建redis-spring-boot-autoconfigure配置工程</strong></li>
</ol>
<p>创建RedisProperties配置文件参数绑定类 </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConfigurationProperties(prefix = &quot;redis&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">RedisProperties</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="type">String</span> <span class="variable">host</span> <span class="operator">=</span> <span class="string">&quot;localhost&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="type">int</span> <span class="variable">port</span> <span class="operator">=</span> <span class="number">6379</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getHost</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> host;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setHost</span><span class="params">(String host)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.host = host;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">getPort</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> port;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setPort</span><span class="params">(<span class="type">int</span> port)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.port = port;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> 创建RedisAutoConfiguration自动配置类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableConfigurationProperties(RedisProperties.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">RedisAutoConfiguration</span> &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 提供Jedis的bean</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> Jedis <span class="title function_">jedis</span><span class="params">(RedisProperties redisProperties)</span> &#123;</span><br><span class="line">       </span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Jedis</span>(redisProperties.getHost(), redisProperties.getPort());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>在resource目录下创建META-INF文件夹并创建spring.factories</p>
<p>注意：”\ “是换行使用的</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">org.springframework.boot.autoconfigure.EnableAutoConfiguration</span>=<span class="string">\</span></span><br><span class="line"><span class="string">  com.itheima.redis.config.RedisAutoConfiguration</span></span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>在springboot-enable工程中引入自定义的redis的starter</strong></li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--自定义的redis的starter--&gt;</span><br><span class="line">      &lt;dependency&gt;</span><br><span class="line">          &lt;groupId&gt;com.itheima&lt;/groupId&gt;</span><br><span class="line">          &lt;artifactId&gt;redis-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">          &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;</span><br><span class="line">      &lt;/dependency&gt;</span><br></pre></td></tr></table></figure>

<p>在SpringbootEnableApplication启动类中测试</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Jedis</span> <span class="variable">jedis</span> <span class="operator">=</span> context.getBean(Jedis.class);</span><br><span class="line">       System.out.println(jedis);</span><br></pre></td></tr></table></figure>

<h2 id="10-SpringBoot自动配置-自定义starter实现-2"><a href="#10-SpringBoot自动配置-自定义starter实现-2" class="headerlink" title="10-SpringBoot自动配置-自定义starter实现-2"></a><strong>10-SpringBoot自动配置-自定义starter实现-2</strong></h2><p>测试springboot-enable工程中的application.properties中的配置参数</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">redis.port</span>=<span class="string">6666</span></span><br></pre></td></tr></table></figure>

<p>使用注解完成有条件加载配置类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableConfigurationProperties(RedisProperties.class)</span></span><br><span class="line"><span class="meta">@ConditionalOnClass(Jedis.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">RedisAutoConfiguration</span> &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 提供Jedis的bean</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="meta">@ConditionalOnMissingBean(name = &quot;jedis&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> Jedis <span class="title function_">jedis</span><span class="params">(RedisProperties redisProperties)</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;RedisAutoConfiguration....&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Jedis</span>(redisProperties.getHost(), redisProperties.getPort());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="11-SpringBoot事件监听"><a href="#11-SpringBoot事件监听" class="headerlink" title="11-SpringBoot事件监听"></a><strong>11-SpringBoot事件监听</strong></h2><p> Java中的事件监听机制定义了以下几个角色：</p>
<p>①事件：Event，继承 java.util.EventObject 类的对象</p>
<p>②事件源：Source ，任意对象Object</p>
<p>③监听器：Listener，实现 java.util.EventListener 接口 的对象</p>
<p>SpringBoot 在项目启动时，会对几个监听器进行回调，我们可以实现这些监听器接口，在项目启动时完成一些操作。</p>
<ul>
<li><p>ApplicationContextInitializer、</p>
</li>
<li><p>SpringApplicationRunListener、</p>
</li>
<li><p>CommandLineRunner、</p>
</li>
<li><p>ApplicationRunner</p>
<p>自定义监听器的启动时机：MyApplicationRunner和MyCommandLineRunner都是当项目启动后执行，使用@Component放入容器即可使用</p>
</li>
</ul>
<p>MyApplicationRunner</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 当项目启动后执行run方法。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyApplicationRunner</span> <span class="keyword">implements</span> <span class="title class_">ApplicationRunner</span> &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">(ApplicationArguments args)</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;ApplicationRunner...run&quot;</span>);</span><br><span class="line">        System.out.println(Arrays.asList(args.getSourceArgs()));</span><br><span class="line">    &#125;</span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure>

<p> MyCommandLineRunner</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyCommandLineRunner</span> <span class="keyword">implements</span> <span class="title class_">CommandLineRunner</span> &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">(String... args)</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;CommandLineRunner...run&quot;</span>);</span><br><span class="line">        System.out.println(Arrays.asList(args));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<p>MyApplicationContextInitializer的使用要在resource文件夹下添加META-INF&#x2F;spring.factories</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">org.springframework.context.ApplicationContextInitializer</span>=<span class="string">com.itheima.springbootlistener.listener.MyApplicationContextInitializer</span></span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">@Component</span><br><span class="line">public class MyApplicationContextInitializer implements ApplicationContextInitializer &#123;</span><br><span class="line">    @Override</span><br><span class="line">    public void initialize(ConfigurableApplicationContext applicationContext) &#123;</span><br><span class="line">        System.out.println(&quot;ApplicationContextInitializer....initialize&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>MySpringApplicationRunListener的使用要添加<strong>构造器</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">public class MySpringApplicationRunListener implements SpringApplicationRunListener &#123;</span><br><span class="line"></span><br><span class="line">    public MySpringApplicationRunListener(SpringApplication application, String[] args) &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void starting() &#123;</span><br><span class="line">        System.out.println(&quot;starting...项目启动中&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void environmentPrepared(ConfigurableEnvironment environment) &#123;</span><br><span class="line">        System.out.println(&quot;environmentPrepared...环境对象开始准备&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void contextPrepared(ConfigurableApplicationContext context) &#123;</span><br><span class="line">        System.out.println(&quot;contextPrepared...上下文对象开始准备&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void contextLoaded(ConfigurableApplicationContext context) &#123;</span><br><span class="line">        System.out.println(&quot;contextLoaded...上下文对象开始加载&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void started(ConfigurableApplicationContext context) &#123;</span><br><span class="line">        System.out.println(&quot;started...上下文对象加载完成&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void running(ConfigurableApplicationContext context) &#123;</span><br><span class="line">        System.out.println(&quot;running...项目启动完成，开始运行&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void failed(ConfigurableApplicationContext context, Throwable exception) &#123;</span><br><span class="line">        System.out.println(&quot;failed...项目启动失败&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="12-SpringBoot流程分析-初始化"><a href="#12-SpringBoot流程分析-初始化" class="headerlink" title="12-SpringBoot流程分析-初始化"></a><strong>12-SpringBoot流程分析-初始化</strong></h2><ol>
<li><p>配置启动引导类（判断是否有启动主类）</p>
</li>
<li><p>判断是否是Web环境</p>
</li>
<li><p>获取初始化类、监听器类</p>
</li>
</ol>
<p><img src="/myl-mm/img/1571369439416.png" alt="1571369439416"></p>
<h2 id="13-SpringBoot流程分析-run"><a href="#13-SpringBoot流程分析-run" class="headerlink" title="13-SpringBoot流程分析-run"></a><strong>13-SpringBoot流程分析-run</strong></h2><ol>
<li><p>启动计时器</p>
</li>
<li><p>执行监听器</p>
</li>
<li><p>准备环境</p>
</li>
<li><p>打印banner：可以resource下粘贴自定义的banner</p>
</li>
<li><p>创建context</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">refreshContext(context);</span><br></pre></td></tr></table></figure>

<p>执行refreshContext方法后才真正创建Bean</p>
</li>
</ol>
<p><img src="/myl-mm/img/1571373793325.png" alt="1571373793325"></p>
<h2 id="14-SpringBoot监控-actuator基本使用"><a href="#14-SpringBoot监控-actuator基本使用" class="headerlink" title="14-SpringBoot监控-actuator基本使用"></a><strong>14-SpringBoot监控-actuator基本使用</strong></h2><p> ①导入依赖坐标</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>②访问<a target="_blank" rel="noopener" href="http://localhost:8080/acruator">http://localhost:8080/acruator</a></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;_links&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;self&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span><span class="punctuation">:</span><span class="string">&quot;http://localhost:8080/actuator&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span><span class="punctuation">:</span><span class="keyword">false</span></span><br><span class="line">        <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;health&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span><span class="punctuation">:</span><span class="string">&quot;http://localhost:8080/actuator/health&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span><span class="punctuation">:</span><span class="keyword">false</span></span><br><span class="line">        <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;health-component-instance&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span><span class="punctuation">:</span><span class="string">&quot;http://localhost:8080/actuator/health/&#123;component&#125;/&#123;instance&#125;&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span><span class="punctuation">:</span><span class="keyword">true</span></span><br><span class="line">        <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;health-component&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span><span class="punctuation">:</span><span class="string">&quot;http://localhost:8080/actuator/health/&#123;component&#125;&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span><span class="punctuation">:</span><span class="keyword">true</span></span><br><span class="line">        <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;info&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span><span class="punctuation">:</span><span class="string">&quot;http://localhost:8080/actuator/info&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span><span class="punctuation">:</span><span class="keyword">false</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="http://localhost:8080/actuator/info">http://localhost:8080/actuator/info</a></p>
<p>在application.properties中配置</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">info.name</span>=<span class="string">lucy</span></span><br><span class="line"><span class="attr">info.age</span>=<span class="string">99</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="http://localhost:8080/actuator/health">http://localhost:8080/actuator/health</a></p>
<p>开启健康检查详细信息</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">management.endpoint.health.show-details</span>=<span class="string">always</span></span><br></pre></td></tr></table></figure>

<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;status&quot;</span><span class="punctuation">:</span><span class="string">&quot;UP&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;details&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;diskSpace&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">            <span class="attr">&quot;status&quot;</span><span class="punctuation">:</span><span class="string">&quot;UP&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">&quot;details&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">                <span class="attr">&quot;total&quot;</span><span class="punctuation">:</span><span class="number">159579508736</span><span class="punctuation">,</span></span><br><span class="line">                <span class="attr">&quot;free&quot;</span><span class="punctuation">:</span><span class="number">13558104064</span><span class="punctuation">,</span></span><br><span class="line">                <span class="attr">&quot;threshold&quot;</span><span class="punctuation">:</span><span class="number">10485760</span></span><br><span class="line">            <span class="punctuation">&#125;</span></span><br><span class="line">        <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;redis&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">            <span class="attr">&quot;status&quot;</span><span class="punctuation">:</span><span class="string">&quot;UP&quot;</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">&quot;details&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">                <span class="attr">&quot;version&quot;</span><span class="punctuation">:</span><span class="string">&quot;2.4.5&quot;</span></span><br><span class="line">            <span class="punctuation">&#125;</span></span><br><span class="line">        <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<h2 id="15-SpringBoot监控-actuator开启所有endpoint"><a href="#15-SpringBoot监控-actuator开启所有endpoint" class="headerlink" title="15-SpringBoot监控-actuator开启所有endpoint"></a><strong>15-SpringBoot监控-actuator开启所有endpoint</strong></h2><p> 开启所有endpoint</p>
<p>在application.properties中配置：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">management.endpoints.web.exposure.include</span>=<span class="string">*</span></span><br></pre></td></tr></table></figure>

<p>开启所有endpoint的返回结果：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">&#123;</span></span><br><span class="line">    <span class="attr">&quot;_links&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">        <span class="attr">&quot;self&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;auditevents&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/auditevents&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;beans&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/beans&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;caches-cache&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/caches/&#123;cache&#125;&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">true</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;caches&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/caches&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;health-component-instance&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/health/&#123;component&#125;/&#123;instance&#125;&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">true</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;health&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/health&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;health-component&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/health/&#123;component&#125;&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">true</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;conditions&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/conditions&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;configprops&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/configprops&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;env&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/env&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;env-toMatch&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/env/&#123;toMatch&#125;&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">true</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;info&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/info&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;loggers&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/loggers&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;loggers-name&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/loggers/&#123;name&#125;&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">true</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;heapdump&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/heapdump&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;threaddump&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/threaddump&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;metrics-requiredMetricName&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/metrics/&#123;requiredMetricName&#125;&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">true</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;metrics&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/metrics&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;scheduledtasks&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/scheduledtasks&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;httptrace&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/httptrace&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;,</span></span><br><span class="line">        <span class="attr">&quot;mappings&quot;</span>:<span class="string">&#123;</span></span><br><span class="line">            <span class="attr">&quot;href&quot;</span>:<span class="string">&quot;http://localhost:8080/actuator/mappings&quot;,</span></span><br><span class="line">            <span class="attr">&quot;templated&quot;</span>:<span class="string">false</span></span><br><span class="line">        <span class="attr">&#125;</span></span><br><span class="line">    <span class="attr">&#125;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br></pre></td></tr></table></figure>

<h2 id="16-SpringBoot监控-springboot-admin图形化界面使用"><a href="#16-SpringBoot监控-springboot-admin图形化界面使用" class="headerlink" title="16-SpringBoot监控-springboot admin图形化界面使用"></a><strong>16-SpringBoot监控-springboot admin图形化界面使用</strong></h2><p>SpringBoot Admin 有两个角色，客户端(Client)和服务端(Server)。</p>
<p>以下为创建服务端和客户端工程步骤：</p>
<p>admin-server：</p>
<p>①创建 admin-server 模块</p>
<p>②导入依赖坐标 admin-starter-server</p>
<p><img src="/myl-mm/img/1571812312998.png" alt="1571812312998"></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>de.codecentric<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-admin-starter-server<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>③在引导类上启用监控功能@EnableAdminServer</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableAdminServer</span></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">SpringbootAdminServerApplication</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        SpringApplication.run(SpringbootAdminServerApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<p>admin-client：</p>
<p>①创建 admin-client 模块</p>
<p>②导入依赖坐标 admin-starter-client</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>de.codecentric<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-admin-starter-client<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>③配置相关信息：server地址等</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 执行admin.server地址</span></span><br><span class="line"><span class="attr">spring.boot.admin.client.url</span>=<span class="string">http://localhost:9000</span></span><br><span class="line"></span><br><span class="line"><span class="attr">management.endpoint.health.show-details</span>=<span class="string">always</span></span><br><span class="line"><span class="attr">management.endpoints.web.exposure.include</span>=<span class="string">*</span></span><br></pre></td></tr></table></figure>

<p>④启动server和client服务，访问server</p>
<h2 id="17-SpringBoot部署"><a href="#17-SpringBoot部署" class="headerlink" title="17-SpringBoot部署"></a><strong>17-SpringBoot部署</strong></h2><p> SpringBoot 项目开发完毕后，支持两种方式部署到服务器：</p>
<p>①jar包(官方推荐)</p>
<p>②war包</p>
<p><strong>更改pom文件中的打包方式为war</strong></p>
<p>修改启动类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> org.springframework.boot.SpringApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.builder.SpringApplicationBuilder;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.web.servlet.support.SpringBootServletInitializer;</span><br><span class="line"></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">SpringbootDeployApplication</span> <span class="keyword">extends</span> <span class="title class_">SpringBootServletInitializer</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        SpringApplication.run(SpringbootDeployApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">protected</span> SpringApplicationBuilder <span class="title function_">configure</span><span class="params">(SpringApplicationBuilder builder)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> builder.sources(SpringbootDeployApplication.class);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<p>指定打包的名称</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">finalName</span>&gt;</span>springboot<span class="tag">&lt;/<span class="name">finalName</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">               <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">               <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://gitee.com/tgreen/myl-mm.git">myl</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://gitee.com/tgreen/myl-mm.git/2022/05/09/02-SpringBoot%E9%AB%98%E7%BA%A7/">https://gitee.com/tgreen/myl-mm.git/2022/05/09/02-SpringBoot%E9%AB%98%E7%BA%A7/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://gitee.com/tgreen/myl-mm.git" target="_blank">阿毛的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myl-mm/tags/springBoot/">springBoot</a></div><div class="post_share"><div class="social-share" data-image="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myl-mm/2022/05/09/01-Springboot-day01/"><img class="prev-cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="onerror=null;src='/myl-mm/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">springBootday01</div></div></a></div><div class="next-post pull-right"><a href="/myl-mm/2022/05/09/%E7%AC%AC%E4%BA%8C%E7%AB%A0%20Redis%E9%AB%98%E7%BA%A7/"><img class="next-cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="onerror=null;src='/myl-mm/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Redis高级</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/myl-mm/2022/05/09/01-Springboot-day01/" title="springBootday01"><img class="cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-09</div><div class="title">springBootday01</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myl-mm/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">myl</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/myl-mm/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/myl-mm/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/myl-mm/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><a id="card-info-btn" href="https://gitee.com/tgreen/"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎观看，又来一个！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#01-SpringBoot%E9%AB%98%E7%BA%A7-%E4%BB%8A%E6%97%A5%E5%86%85%E5%AE%B9"><span class="toc-number">1.</span> <span class="toc-text">01-SpringBoot高级-今日内容</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#02-SpringBoot%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE-Condition-1"><span class="toc-number">2.</span> <span class="toc-text">02-SpringBoot自动配置-Condition-1</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#03-SpringBoot%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE-Condition-2"><span class="toc-number">3.</span> <span class="toc-text">03-SpringBoot自动配置-Condition-2</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#04-SpringBoot%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE-%E5%88%87%E6%8D%A2%E5%86%85%E7%BD%AEweb%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="toc-number">4.</span> <span class="toc-text">04-SpringBoot自动配置-切换内置web服务器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#05-SpringBoot%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE-Enable%E6%B3%A8%E8%A7%A3%E5%8E%9F%E7%90%86"><span class="toc-number">5.</span> <span class="toc-text">05-SpringBoot自动配置-Enable注解原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10-SpringBoot%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE-%E8%87%AA%E5%AE%9A%E4%B9%89starter%E5%AE%9E%E7%8E%B0-2"><span class="toc-number">6.</span> <span class="toc-text">10-SpringBoot自动配置-自定义starter实现-2</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11-SpringBoot%E4%BA%8B%E4%BB%B6%E7%9B%91%E5%90%AC"><span class="toc-number">7.</span> <span class="toc-text">11-SpringBoot事件监听</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12-SpringBoot%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90-%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="toc-number">8.</span> <span class="toc-text">12-SpringBoot流程分析-初始化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#13-SpringBoot%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90-run"><span class="toc-number">9.</span> <span class="toc-text">13-SpringBoot流程分析-run</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#14-SpringBoot%E7%9B%91%E6%8E%A7-actuator%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8"><span class="toc-number">10.</span> <span class="toc-text">14-SpringBoot监控-actuator基本使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#15-SpringBoot%E7%9B%91%E6%8E%A7-actuator%E5%BC%80%E5%90%AF%E6%89%80%E6%9C%89endpoint"><span class="toc-number">11.</span> <span class="toc-text">15-SpringBoot监控-actuator开启所有endpoint</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#16-SpringBoot%E7%9B%91%E6%8E%A7-springboot-admin%E5%9B%BE%E5%BD%A2%E5%8C%96%E7%95%8C%E9%9D%A2%E4%BD%BF%E7%94%A8"><span class="toc-number">12.</span> <span class="toc-text">16-SpringBoot监控-springboot admin图形化界面使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#17-SpringBoot%E9%83%A8%E7%BD%B2"><span class="toc-number">13.</span> <span class="toc-text">17-SpringBoot部署</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/RabbitMQ%20Windows%20%E5%AE%89%E8%A3%85/" title="RabbitMQ Windows 安装"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="RabbitMQ Windows 安装"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/RabbitMQ%20Windows%20%E5%AE%89%E8%A3%85/" title="RabbitMQ Windows 安装">RabbitMQ Windows 安装</a><time datetime="2022-05-09T09:04:30.600Z" title="发表于 2022-05-09 17:04:30">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/" title="Spring Cloud Gateway 内置的过滤器工厂"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Spring Cloud Gateway 内置的过滤器工厂"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/" title="Spring Cloud Gateway 内置的过滤器工厂">Spring Cloud Gateway 内置的过滤器工厂</a><time datetime="2022-05-09T09:04:19.065Z" title="发表于 2022-05-09 17:04:19">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/Turbine%E6%90%AD%E5%BB%BA%E6%AD%A5%E9%AA%A4/" title="Turbine"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Turbine"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/Turbine%E6%90%AD%E5%BB%BA%E6%AD%A5%E9%AA%A4/" title="Turbine">Turbine</a><time datetime="2022-05-09T09:04:13.000Z" title="发表于 2022-05-09 17:04:13">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/Eureka%20%E5%85%A8%E9%83%A8%E9%85%8D%E7%BD%AE%20/" title="Euraka配置详解"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Euraka配置详解"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/Eureka%20%E5%85%A8%E9%83%A8%E9%85%8D%E7%BD%AE%20/" title="Euraka配置详解">Euraka配置详解</a><time datetime="2022-05-09T09:03:49.699Z" title="发表于 2022-05-09 17:03:49">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/01-Springboot-day01/" title="springBootday01"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="springBootday01"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/01-Springboot-day01/" title="springBootday01">springBootday01</a><time datetime="2022-05-09T09:03:15.476Z" title="发表于 2022-05-09 17:03:15">2022-05-09</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By myl</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myl-mm/js/utils.js"></script><script src="/myl-mm/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>